/**
 * [OElove] (C)2010-2099 OELOVE.COM Inc. X
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * This is NOT a freeware, use is subject to license terms
 * $ Last update 2017/03/21 by CL $
*/
$(function(){

	//保存消息提醒
	$(document).on("click", "[f='but_save_set']", function(){
		$_mod = $(this).attr("data-mod");
		$_value = 0;
		if ($(this).hasClass("current")) {
			$(this).removeClass("current");
		}
		else {
			$(this).addClass("current");
			$_value = 1;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=set",
			cache: false,
			data: {a:"saveset", mod:$_mod, value:$_value, datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {

				}
				else {

				}
			},
			error: function() {
			}
		});
	});
	

	//打开修改密码窗
	$(document).on("click", "[f='but_open_password']", function(){
		$_url = _OE_FILE + "&c=set&a=password";
		oeShadeBox("mypassword", "ajax", $_url, 550, 340);
	});

	//保存新密码
	$(document).on("click", "[f='but_save_edit_password']", function(){
		$oldpassword = $("#oldpassword").val();
		$newpassword = $("#newpassword").val();
		$confirmpassword = $("#confirmpassword").val();
		if ($oldpassword.length == 0) {
			ToastShow("请输入旧密码");
			return false;
		}
		if ($newpassword.length == 0) {
			ToastShow("请输入新密码");
			return false;
		}
		if ($confirmpassword.length == 0) {
			ToastShow("请输入确认密码");
			return false;
		}
		if ($confirmpassword != $newpassword) {
			ToastShow("确认密码不正确");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=set",
			cache: false,
			data: {a:"savepassword", oldpassword:$oldpassword, newpassword:$newpassword, confirmpassword:$confirmpassword, datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("mypassword");
					ToastShow("修改成功，请记住新密码！");

				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("修改失败");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//打开安全密码
	$(document).on("click", "[f='but_open_payword']", function(){
		$_url = _OE_FILE + "&c=set&a=payword";
		oeShadeBox("pop_edit_payword", "ajax", $_url, 500, 300);
	});

	//保存安全密码
	$(document).on("click", "[f='but_save_edit_payword']", function(){
		$oldword = $("#oldword").val();
		if (typeof($oldword) == "undefined") {
			$oldword = "";
		}
		else {
			if ($oldword.length == 0) {
				ToastShow("请输入旧密码");
				return false;
			}
		}
		$newword = $("#newword").val();
		$confirmword = $("#confirmword").val();
		if ($newword.length == 0) {
			ToastShow("请输入新密码");
			return false;
		}
		if ($confirmword.length == 0) {
			ToastShow("请输入确认密码");
			return false;
		}
		if ($confirmword != $newword) {
			ToastShow("确认密码不正确");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=set",
			cache: false,
			data: {a:"savepayword", oldword:$oldword, newword:$newword, confirmword:$confirmword, datatype:"json", r:get_rndnum(8)},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("pop_edit_payword");
					ToastShow("修改成功，请记住新安全密码！");

				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("修改失败");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});


	//打开收款资料
	$(document).on("click", "[f='but_open_bank']", function(){
		$_url = _OE_FILE + "&c=set&a=bank";
		oeShadeBox("pop_edit_bank", "ajax", $_url, 600, 470);
	});
	//选择收款方式
	$(document).on("click", "[f='select_banktype']", function(){
		$_type = $(this).attr("data-type");
		$("[f='select_banktype']").removeClass("current");
		$(this).addClass("current");

		if ($_type == "alipay") {
			$("#bankname").val("支付宝");
			$("#bankaccount").val("");
			$("#bankaccount").attr("placeholder", "请填写支付宝帐号");
			$(".bank").hide();
		}
		else {
			$("#bankname").val("");
			$("#bankaccount").val("");
			$("#bankaccount").attr("placeholder", "请填写银行卡号");
			$(".bank").show();
		}
	});

	//保存收款资料
	$(document).on("click", "[f='but_save_edit_bank']", function(){
		$bankname = $("#bankname").val();
		$banksub = $("#banksub").val();
		$bankaccount = $("#bankaccount").val();
		$payword = $("#payword").val();

		if ($bankname.length == 0) {
			ToastShow("请填写收款方开户行");
			return false;
		}
		if ($bankaccount.length == 0) {
			ToastShow("请填写收款方账号");
			return false;
		}
		if ($payword.length == 0) {
			ToastShow("请输入安全密码");
			return false;
		}
		$.ajax({
			type: "POST",
			url: _OE_FILE + "&c=set",
			cache: false,
			data: {
					a:"savebank", bankname:$bankname, banksub:$banksub, 
					bankaccount:$bankaccount, payword:$payword, datatype:"json", r:get_rndnum(8)
			},
			dataType: "json",
			success: function($data) {
				$json = eval($data);
				$response = $json.response;
				$result = $json.result;
				if ($response == "1") {
					_closeShadeBox("pop_edit_bank");
					ToastShow("收款资料修改成功");

				}
				else {
					if ($result.length > 0) {
						ToastShow($result);
					}
					else {
						ToastShow("修改失败");
					}
				}
			},
			error: function() {
				ToastShow("系统繁忙，请稍后再试");
			}
		});

	});



});